package com.ruoyi.account.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
public enum RecordStatusEnum {

    /**
     * （-1 不可用）（0 待确认）（1 待处理）（2 已入账）
     */
    UNABLE(-1, "不可操作"),
    WAIT_CONFIRM(0, "待确认"),
    WAIT_HANDLE(1, "待入账"),
    SUCCESS(2, "已入账"),
    ;

    Integer value;
    String name;

    RecordStatusEnum(Integer value, String name){
        this.value = value;
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public static String getLabelByValue(Integer value) {
        for (RecordStatusEnum item : values()) {
            if (ObjectUtil.equals(item.getValue(), value)){
                return item.getName();
            }
        }
        return value+"";
    }

    public static List<Map<String, String>> getListMap() {
        List<Map<String, String>> listMap = new ArrayList<>();
        for (RecordStatusEnum item : values()) {
            if (ObjectUtil.equal(item.getValue(), UNABLE.getValue())){
                continue;
            }
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("name", item.getName());
            itemMap.put("value", String.valueOf(item.getValue()));
            listMap.add(itemMap);
        }
        return listMap;
    }

    public static List<Map<String, String>> getListEditMap() {
        List<Map<String, String>> listMap = new ArrayList<>();
        for (RecordStatusEnum item : values()) {
            if (ObjectUtil.equal(item.getValue(), UNABLE.getValue()) ||
                    ObjectUtil.equal(item.getValue(), SUCCESS.getValue())){
                continue;
            }
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("name", item.getName());
            itemMap.put("value", String.valueOf(item.getValue()));
            listMap.add(itemMap);
        }
        return listMap;
    }

}
